<div class="sc_body">
    <form action="{$view['id']?U('save'):U('add')}?spm={$spm}" id="form" class="layui-form layui-form-pane">
        <input type="hidden" name="id" value="{$view.id|default=''}" />
        <input type="hidden" name="gid" id="gid" value="{$view.gid|default=NOW_TIME}" />
        <div class="sc_title sc_body_title">
            <h5>{$nodeInfo.title}</h5>
            <div class="sc_title_btn">
                <button type="submit" class='layui-btn layui-btn-sm'><i class='layui-icon'>&#xe605;</i> 保存</button>
                <button class='layui-btn layui-btn-sm layui-btn-primary' onclick="window.history.back();return false;"><i class="layui-icon">&#x1006;</i> 返回</button>
            </div>
        </div>
        <div class="fadeInUp animated">
            <section class="sc_layout_inner layui-clear">
                <div class="sc_editor_content">
                    <div class="layui-form-item">
                        <label class="layui-form-label label-required">标题</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" value="{$view.title|default=''}" placeholder="产品标题" datatype="*" nullmsg="请输入标题!" autocomplete="off" class="layui-input" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-row layui-col-space15">
                            <div class="layui-col-md6">
                                <label class="layui-form-label">规格</label>
                                <div class="layui-input-block">
                                    <input type="text" name="dimension" value="{$view.dimension|default=''}" placeholder="规格" class="layui-input" />
                                </div>
                            </div>
                            <div class="layui-col-md6">
                                <label class="layui-form-label">编码 | 条码</label>
                                <div class="layui-input-block">
                                    <input type="text" name="code" value="{$view.code|default=''}" placeholder="编码 | 条码" class="layui-input" />
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-row layui-col-space15">
                            <div class="layui-col-md6">
                                <label class="layui-form-label">价格</label>
                                <div class="layui-input-block">
                                    <input type="text" name="price" value="{$view.price|default=''}" placeholder="价格" class="layui-input" />
                                </div>
                            </div>
                            <div class="layui-col-md6">
                                <label class="layui-form-label">单位</label>
                                <div class="layui-input-block">
                                    <input type="text" name="unit" value="{$view.unit|default=''}" placeholder="单位" class="layui-input" />
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">产品概述</label>
                        <div class="layui-input-block">
                            <textarea name="description" placeholder="产品概述" class="layui-textarea">{$view.description|default=''}</textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">发布时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="create_time" value="{$view.create_time|default=''}" placeholder="当前时间" class="layui-input sc_form_date" readonly="" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <script name="content" type="text/plain" id="content" style="width:736px;height:350px;">{$view.content|default=''|htmlspecialchars_decode}</script>
                    </div>
                </div>
                <div class="sc_editor_sidebar">
                    <div class="layui-form-item">
                        <label class="layui-form-label">附属分类</label>
                        <div class="layui-input-block">
                            <select name="nid_other" lay-filter="category">
                                <option value="0">若无需求，可不选！</option>
                                {volist name="category" id="data"}
                                    <option value="{$data.id}" {if condition="$nodeInfo['id'] == $data['id'] || $nodeInfo['mid'] !== $data['mid'] || $data['children'] == 1"}disabled{/if} {$view.nid_other|default=''==$data.id?'selected':''}>{$data.delimiter}{$data.pid?'├':''} {$data.title}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item from_item_image">
                        <div class="img_label">
                            <label>封面图</label>
                            <a id="btn_upload_thumb"></a>
                            <span><i class="layui-icon" data-tips-text="推荐尺寸 720x720">&#xe6b2;</i></span>
                        </div>
                        <div id="thumb_view" class="img_item transition" style="background-image:url('{$view.thumb|default='__Base__/images/noimg.png'}')">
                            <img layer-src="{$view.thumb|default='__Base__/images/noimg.png'}" src="__Base__/images/alpha.png">
                            <input type="hidden" name="thumb" value="{$view.thumb|default=''}">
                        </div>
                    </div>
                    <div class="layui-form-item from_item_image">
                        <div class="img_label">
                            <label>图册</label>
                            <a id="btn_upload_gallery"></a>
                            <span><i class="layui-icon" data-tips-text="推荐尺寸 720x720">&#xe6b2;</i></span>
                        </div>
                        <input type="hidden" name="photos" value="{$view.photos|default=''}">
                        <div id="photos_view" class="img_item_box transition nowrap">
                            {volist name="gallery" id="data"}
                                <div class="img_item transition" style="background-image:url({$data.image_src})">
                                    <img layer-src="{$data.image_src}" src="__Base__/images/alpha.png">
                                </div>
                            {/volist}
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">购买链接</label>
                        <div class="layui-input-block">
                            <input type="text" name="url" value="{$view.url|default=''}" placeholder="购买链接" class="layui-input" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">阅读数</label>
                        <div class="layui-input-block">
                            <input type="text" name="count" value="{$view.count|default='0'}" placeholder="阅读数默认为0" class="layui-input" />
                        </div>
                    </div>
                    <div class="layui-form-item" pane="">
                        <label class="layui-form-label">属性</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="is_status" value="1" title="启用" lay-skin="primary" {eq name="view['is_status']|default='1'" value="1"}checked{/eq} />
                            <input type="checkbox" name="is_recommend" value="1" title="推荐" lay-skin="primary" {eq name="view['is_recommend']|default='0'" value="1"}checked{/eq} />
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </form>
</div>
<script>
    UE.delEditor('content');
    UE.getEditor('content');
    lay('.sc_form_date').each(function(){
        layui.laydate.render({
            elem: this
            ,trigger: 'click'
            ,type: 'datetime'
        });
    });
    $(document).ready(function() {
        //图片预览
        layer.photos({photos: '#thumb_view',shade: 0.7,anim: 5});
        layer.photos({photos:'#photos_view', shade:0.7, anim:5});
    });
    $('#btn_upload_thumb').uploadify({
        'swf'      : '/Public/plugs/uploadify/uploadify.swf',
        'uploader' : '{:U("Uploads/upload")}',
        'multi' : false,
        'buttonClass' : '',
        'buttonText' : '本地上传',
        'width' : 110,
        'height' : 36,
        'onUploadSuccess' : function(file, data, response) {
            var allData = eval('(' + data + ')');
            if(allData.status == 1){
                $("#thumb_view").css("background-image","url("+allData.image_src+")");
                $("#thumb_view").find('img').attr('layer-src', allData.image_src);
                $("#thumb_view").find('input').val(allData.image_src);
            }else{
                var timer;
                layer.open({
                    content: allData.info,
                    closeBtn: 0,
                    icon: 2,
                    btn:[],
                    success: function(a,b){
                        var i = 1;
                        var fn = function() {
                            layer.title(i + ' 秒后自动关闭。',b);
                            if(!i) {layer.close(b); return false;} i--;
                        };
                        timer = setInterval(fn, 1000);
                        fn();
                    },
                    cancel: function(i){
                        return false;
                    },
                    end: function(){clearInterval(timer);}
                });
            }
        },
    });
    //uploadify上传图册
    $('#btn_upload_gallery').uploadify({
        'formData'     : {
            'timestamp' : "",//当前时间戳由后台传过来的
            'token'     : '6b79a77180e9ec3a7ca351ebe54641a2'//用md5生成token
        },
        'swf'      : '/Public/plugs/uploadify/uploadify.swf',
        'uploader' : '{:U("Uploads/upload",array("type"=>"gallery"))}',//后台上传文件处理方法
        'multi' : true,
        'buttonClass' : '',
        'buttonText' : '本地上传',
        'width' : 110,
        'height' : 36,
        'onUploadSuccess' : function(file, data, response) {
            var data=eval('('+data+')');
            if(data.status == 0){
                layer.open({
                    content: data.info,
                    closeBtn: 0,
                    icon: 2,
                    btn:[],
                    success: function(a,b){
                        var i = 1;
                        var fn = function() {
                            layer.title(i + ' 秒后自动关闭。',b);
                            if(!i) {layer.close(b); return false;} i--;
                        };
                        timer = setInterval(fn, 1000);
                        fn();
                    },
                    cancel: function(i){
                        return false;
                    },
                    end: function(){clearInterval(timer);}
                });
            }else{
                put_img(data['image_src']);//添加图片到img_box
            }
        }
    });
    //添加图片到img_box
    function put_img(savepath){
        var gid       = $('#gid').val();
        var new_img =  '<div class="img_item transition" style="background-image:url(' + savepath + ')"><img layer-src="' + savepath + '" src="__Base__/images/alpha.png"></div>';
        $('#photos_view').append(new_img);
        var url = '{:U("Uploads/photoAdd")}';
        $.post(url,{image_src:savepath, gid:gid},function(data){});
    }
</script>
